// JavaScript Document
var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_gecko = (navigator.product=='Gecko');

//check used
function getObj(id){
	return document.getElementById(id);
}
function showselect(type){
	var selects = get_tags(document,'select');
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility = type;
	}
}

function get_tags(parentobj,tag){
	if (typeof parentobj.getElementsByTagName!='undefined') {
		return parentobj.getElementsByTagName(tag);
	} else if (parentobj.all && parentobj.all.tags) {
		return parentobj.all.tags(tag);
	} else {
		return null;
	}
}
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
function getTop() {
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:ietruebody().scrollTop;
}
function getLeft() {
	return (typeof window.pageXOffset != 'undefined' ? window.pageXOffset:ietruebody().scrollLeft)
}
//other function
function CheckAll(form){
	var ifcheck = null;
	for (var i=0;i<form.elements.length-2;i++){
		var e = form.elements[i];
		if(e.type=='checkbox' && e.name != 'checkAll'){
			if (ifcheck === null) ifcheck = !e.checked;
			e.checked = ifcheck;
			if (typeof e.onclick == 'function') e.onclick();
		}
	}
	return ifcheck;
}
function countChecked(form){
	var cnt = 0;
	for (var i=0;i<form.elements.length-2;i++){
		var e = form.elements[i];
		if(e.type=='checkbox' && e.name != 'checkAll'){
			if(e.checked) cnt++;
		}
	}
	return cnt;
}

function batch_confirm(f){
	var cnt = countChecked(f);
	var s = document.getElementById('do');
	var todo = s.options[s.selectedIndex].innerHTML;
	var str = "";
	if(cnt == 0){
	
		str += "操作:" + todo +"\n\n";
		str += "错误:你还没有选中要操作的条目。请选中条目后再执行该操作。\n";
		alert(str);
		return false;
	} else {
		str += "操作:" + todo +"\n\n";
		str += "待操作的条目数量:" + cnt +"\n\n";
		str += "你确定要执行吗？\n";
		
		return confirm(str);
	}
}
function searchFormSubmit(f){
	var el = new Array();
	
	for(var i=0; i<f.elements.length; i++){
		el[i] = f.elements[i].name + '=' +  encodeURI(f.elements[i].value);
	}
	var par = el.join('&');
	var base_url = f.action;
	var q = -1 == base_url.indexOf('?') ? "?" : "&";
	location.href = f.action +q+par;
	return false;
}
function atccheck(){
	if(document.FORM.atc_title.value==''){
		alert('');
		document.FORM.atc_title.focus();
		return false;
	} else if(document.FORM.fid.value==''){
		alert('');
		document.FORM.fid.focus();
		return false;
	}
	_submit();
}
function report_jump(admin_file){
	var URL=document.form1.type.options[document.form1.type.selectedIndex].value;
	location.href=admin_file+"?adminjob=report&type="+URL;
}
function level_jump(admin_file){
	var URL=document.mod.selectfid.options[document.mod.selectfid.selectedIndex].value;
	location.href=admin_file+"?adminjob=level&action=editgroup&gid="+URL;
}
function ip_jump(name){
	URL = eval('document.form1.' + name + '.options[document.form1.' + name + '.selectedIndex].value');
	location.href=URL;
}
function pwJsCheck(_this,check,tagName){
	try{
		if (typeof tagName == 'undefined') tagName = "tr";
		if (typeof check == 'undefined') {
			if (typeof _this.checked == 'boolean') {
				check = _this.checked;
			} else {
				check = false;
			}
		}
		var o = _this.parentNode;
		var i = 3;
		while(i--){
			if (o.nodeName.toLowerCase() == tagName) {
				var className =  o.className.replace(/\s?checked/ig, "");
				if (check) {
					className +=' checked';
				}
				o.className = className;
				break;
			} else {
				o = o.parentNode;
			}
		}
	}catch(e){}
}
//Cookies Function
function getCookie(name) {
    var start = document.cookie.indexOf(name + '=');
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start==-1) {
        return null;
    }
    var end = document.cookie.indexOf(';', len);
    if (end == -1) {
        end = document.cookie.length;
    }
    return unescape(document.cookie.substring(len,end));
}
function setCookie(name, value, expires, path, domain, secure) {
	if (!expires) {
		expires = new Date();
		expires.setTime(expires.getTime()+31536000);
	}
	document.cookie = name + '=' + escape(value) +
        ( (expires) ? ';expires=' + expires.toGMTString() : '') +
        'path=' + ( (path) ? path : '/') +
        ( (domain)  ? ';domain=' + domain : '') +
        ( (secure)  ? ';secure' : '');
}
function IsElement(id) {
	return document.getElementById(id) != null ? true : false;
}
function elementBind(type,id,stylename,csstext){
	var element = document.createElement(type);
	if (id) {
		element.id = id;
	}
	if (typeof(stylename) == 'string') {
		element.className = stylename;
	}
	if (typeof(csstext) == 'string') {
		element.style.cssText = csstext;
	}
	return element;
}
function addChild(parent,type,id,stylename,csstext){
	parent = objCheck(parent);
	var child = elementBind(type,id,stylename,csstext);
	parent.appendChild(child);
	return child;
}

function delElement(id){
	id = objCheck(id);
	id.parentNode.removeChild(id);
}
function objCheck(obj) {
	if (typeof(obj)=='string') {
		obj	= getObj(obj);
	}
	return obj;
}
